<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>支出审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__TMPL__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__TMPL__/css/admin.css" media="all">
    <script type="text/javascript" src="__TMPL__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__TMPL__/layui/layui.js"></script>
    <script type="text/javascript" src="__TMPL__/js/admin.js"></script>
    <script type="text/javascript" src="__TMPL__/layui/lay/modules/util.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="loginname" placeholder="请输入关键词" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="time" placeholder="请选择日期">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <select name="role">
                            <option value="0">管理员</option>
                            <option value="1">超级管理员</option>
                            <option value="2">纠错员</option>
                            <option value="3">采购员</option>
                            <option value="4">推销员</option>
                            <option value="5">运营人员</option>
                            <option value="6">编辑</option>
                        </select><div class="layui-unselect layui-form-select"><div class="layui-select-title"><input type="text" placeholder="请选择" value="管理员" readonly="" class="layui-input layui-unselect"><i class="layui-edge"></i></div><dl class="layui-anim layui-anim-upbit"><dd lay-value="0" class="layui-this">管理员</dd><dd lay-value="1" class="">超级管理员</dd><dd lay-value="2" class="">纠错员</dd><dd lay-value="3" class="">采购员</dd><dd lay-value="4" class="">推销员</dd><dd lay-value="5" class="">运营人员</dd><dd lay-value="6" class="">编辑</dd></dl></div>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit="" lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                    <button class="layui-btn layuiadmin-btn-admin layui-btn-normal" lay-submit="" lay-filter="add">
                        <i class="layui-icon layui-icon-add-circle-fine layuiadmin-button-btn" style="top: -2px"></i>添加
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
            <script type="text/html" id="options">
                <div class="layui-btn-group">
                    <button class="layui-btn layui-btn-sm layui-btn-normal" type="button" lay-event="browse">
                        查看图片
                    </button>
                </div>
            </script>
            <script type="text/html" id="toolbar">
                <div class="layui-inline" title="通过" lay-event="pass">
                    <i class="layui-icon layui-icon-ok"></i>
                </div>
                <div class="layui-inline" title="拒绝" lay-event="refuse">
                    <i class="layui-icon layui-icon-close"></i>
                </div>
            </script>
        </div>
    </div>
</div>
<script type="text/html" id="check">
    <input type="radio" name="layTableCheckbox" value="{{d.id}}" lay-filter="check">
</script>
<script>
    layui.config({
        base: '__TMPL__/public/', //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form','admin','upload','table'], function(){
        var $ = layui.$
            ,form = layui.form
            ,admin = layui.admin
            ,table = layui.table;
        //用户表格初始化
        var dataTable = table.render({
            elem: '#dataTable'
            , url: "{:url('expenses/review_data')}" //数据接口
            ,toolbar: '#toolbar'
            , page: true //开启分页
            , response: {
                statusCode: 1
            }
            , cols: [[ //表头
                {checkbox: true, fixed: true}
                ,{field: 'name', title: "姓名"}
                , {field: 'apply_time', title: "时间",width:200}
                , {field: 'money', title: "金额"}
                , {field: 'remark', title: "用途"}
                , {fixed: 'right', title: '操作', align: 'left', toolbar: '#options'}
            ]]
        });

        table.on('tool(dataTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'browse') {
                $.getJSON('/admin/expenses/get_img?id='+data.id, function(json){
                    layer.photos({
                        photos: json
                        ,anim: 5
                    });
                })
            }else if (obj.event === 'delete') {
                var del = layer.confirm('确定要删除吗？', {
                    btn: ['删除', '暂不'] //按钮
                }, function () {
                    /*
                    执行删除
                    */
                });
            }
        });

        table.on('toolbar(dataTable)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            var ids = [];
            if (data.length>0){
                $.each(data,function (index,element) {
                    ids.push(element.id)
                })
            }else{
                layer.msg('请选择要操作的数据！');return false;
            }

            switch(obj.event){
                case 'pass':
                    admin.req({
                        url: "{:url('baoxiao/do_review')}",
                        method:'post',
                        type:'json',
                        data: {'id':ids,'type':1},
                        done:function (res) {
                            if(res.code===1){
                                layer.msg(res.msg, function(){
                                    dataTable.reload();
                                });
                            }else{
                                layer.msg(res.msg, {icon: 5});
                            }
                        }
                    });
                    break;
                case 'refuse':
                    admin.req({
                        url: "{:url('baoxiao/do_review')}",
                        method:'post',
                        type:'json',
                        data: {'id':ids,'type':2},
                        done:function (res) {
                            if(res.code===1){
                                layer.msg(res.msg, function(){
                                    dataTable.reload();
                                });
                            }else{
                                layer.msg(res.msg, {icon: 5});
                            }
                        }
                    });
                    break;
            };
        });
    });

    function time2date(t) {
        var t1 = parseInt(t + '000');
        return layui.util.toDateString(t1);
    }
</script>
</body>
</html>